#!/usr/bin/python
# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt

files = ['2011-11-23.stat',  '2011-11-24.stat',  '2011-11-25.stat',  '2011-11-26.stat',
         '2011-11-27.stat',  '2011-11-28.stat',  '2011-11-29.stat',  '2011-11-30.stat',
         '2011-12-01.stat',  '2011-12-02.stat']

dict = {}
file = open(files[0], 'r')
for line in file.readlines():
    part = line.split()
    if part[0] == 'id:':
        cur_id = part[1]
        dict[cur_id] = []
    else:
        # pv, totalcomment, fav, up, down, reference
        dict[cur_id].append(part[1])
file.close()

for i in range(1, 10):
    file = open(files[i], 'r')
    for line in file.readlines():
        part = line.split()
        if part[0] == 'id:':
            cur_id = part[1]
        elif dict.has_key(cur_id):
            dict[cur_id].append(part[1])
    file.close()

plt.xlabel('day')
plt.ylabel('pv')
for id in dict:
    x = np.arange(1, 11, 1)
    y = []
    for i in range(0, 10):
    	y.append(float(dict[id][i * 6]))
    plt.plot(x, y)

plt.axis([1, 10, 0, 4000000])
plt.savefig('pv')
plt.clf()

plt.xlabel('day')
plt.ylabel('totalcomment')
for id in dict:
    x = np.arange(1, 11, 1)
    y = []
    for i in range(0, 10):
    	y.append(float(dict[id][i * 6 + 1]))
    plt.plot(x, y)

plt.axis([1, 10, 0, 6000])
plt.savefig('totalcomment')
plt.clf()

plt.xlabel('day')
plt.ylabel('fav')
for id in dict:
    x = np.arange(1, 11, 1)
    y = []
    for i in range(0, 10):
    	y.append(float(dict[id][i * 6 + 2]))
    plt.plot(x, y)

plt.axis([1, 10, 0, 1000])
plt.savefig('fav')
plt.clf()

plt.xlabel('day')
plt.ylabel('up')
for id in dict:
    x = np.arange(1, 11, 1)
    y = []
    for i in range(0, 10):
    	y.append(float(dict[id][i * 6 + 3]))
    plt.plot(x, y)

plt.axis([1, 10, 0, 40000])
plt.savefig('up')
plt.clf()

plt.xlabel('day')
plt.ylabel('down')
for id in dict:
    x = np.arange(1, 11, 1)
    y = []
    for i in range(0, 10):
    	y.append(float(dict[id][i * 6 + 4]))
    plt.plot(x, y)

plt.axis([1, 10, 0, 10000])
plt.savefig('down')
plt.clf()

plt.xlabel('day')
plt.ylabel('reference')
for id in dict:
    x = np.arange(1, 11, 1)
    y = []
    for i in range(0, 10):
    	y.append(float(dict[id][i * 6 + 5]))
    plt.plot(x, y)

plt.axis([1, 10, 0, 500000])
plt.savefig('reference')
plt.clf()
